//
//  LZFFileTool.m
//  LZFBuDieJie
//
//  Created by 梁梓烽 on 16/6/23.
//  Copyright © 2016年 liangzifeng. All rights reserved.
//

#import "LZFFileTool.h"

@implementation LZFFileTool

+(NSInteger)getFileCache:(NSString *)cacheDirectoryPath
{
    
    NSFileManager *mgr=[NSFileManager defaultManager];
    
    NSArray *subsArray =  [mgr subpathsOfDirectoryAtPath:cacheDirectoryPath error:nil];
    
    NSInteger totalSise =0;
    for (NSString *subPaths in subsArray) {
        NSString *fullPaths =   [cacheDirectoryPath stringByAppendingPathComponent:subPaths];
        
        BOOL isDirectory;
        BOOL isExist =   [mgr fileExistsAtPath:fullPaths isDirectory:&isDirectory];
        
        //文件过滤(.DS文件过滤掉,文件夹过滤掉,不是文件也是过滤掉)
        if ([fullPaths containsString:@".DS"])continue;
        if (!isExist || isDirectory) continue;
        
        NSDictionary *attDic= [mgr attributesOfItemAtPath:fullPaths error:nil];
        
        totalSise=totalSise+[attDic fileSize];
        
        
    }
    
    NSLog(@"%ld",totalSise);
    return  totalSise;
}


+(void)removeFileCache:(NSString *)cacheDirectoryPath
{
    
    
    NSFileManager *mgr=[NSFileManager defaultManager];
    
    NSArray *contentArray = [mgr contentsOfDirectoryAtPath:cacheDirectoryPath error:nil];
    
    for (NSString *contentPath in contentArray) {
        NSString *fullPath =  [cacheDirectoryPath stringByAppendingPathComponent:contentPath];
        
        [mgr removeItemAtPath:fullPath error:nil];
    }

}

@end
